/**
 * Created by Aigo on 2017/05/31.
 */
$(function () {
    var sort = 102;
    var eid = GetQueryString("eid");
    getData(eid);

    //修改MET直播
    $("#updateData").on("click", function () {
        var loginName = window.localStorage.getItem("loginName");
        $("#sort").val(sort);
        $("#createUser").val(loginName);
        $("#addForm").attr("action", getAdminIP() + "lives/" + eid);
        $("#addForm").submit();
    })

    //取消修改MET直播
    $("#cancelUpdate").on("click", function () {
        window.history.go(-1);
    })

    //根据eid，查询数据
    function getData(id) {
        var sel = $.Params.create();
        sel.addParams("page", 0);
        sel.addParams("rows", rows);
        getPageData("GET", sel, getAdminIP() + "lives/" + id, function (data) {
            if (data.success) {
                var val = data.result;
                $("#loadImg").attr("src", "../data/expertImg/" + val.expertHeadImg);
                $("#expertName").val(val.expertName);
                $("#expertHospital").val(val.expertHospital);
                $("#title").val(val.title);
                $("#displayTime").val(val.displayTime);
                $("#startTime").val(val.startTime);
                $("#endTime").val(val.endTime);
                $("#url").val(val.url);
                $("#scoreC").val(val.scoreC);
                $("#description").val(val.description);
            }
        })
    }

    //日期控件
    var startTime = {
        dateCell: "#startTime",
        format: 'YYYY-MM-DD hh:mm:ss',
        isinitVal: false,
        festival: false,
        ishmsVal: false,
        isTime: true,
        maxDate: '2099-06-16 23:59:59'
    };
    jeDate(startTime);
    var endTime = {
        dateCell: "#endTime",
        format: 'YYYY-MM-DD hh:mm:ss',
        isinitVal: false,
        festival: false,
        ishmsVal: false,
        isTime: true,
        maxDate: '2099-06-16 23:59:59'
    };
    jeDate(endTime);

    //实时预览图片
    $("#picUrl").on("change", function (e) {
        var src, url = window.URL || window.webkitURL || window.mozURL, files = e.target.files;
        for (var i = 0, len = files.length; i < len; ++i) {
            var file = files[i];

            if (url) {
                src = url.createObjectURL(file);
            } else {
                src = e.target.result;
            }

            $("#loadImg").attr('src', src);
        }
    });
});
